package pers.cz.chat.filter;

import io.netty.channel.Channel;
import pers.cz.chat.constants.Commands;
import pers.cz.chat.constants.JefClolorEnum;
import pers.cz.chat.utils.LogUtils;
import pers.cz.netty.filter.FilterHandler;
import pers.cz.netty.filter.FilterHandlerContext;
import pers.cz.netty.protocal.Message;

/**
 * @version 1.0
 * @description:
 * @author: ChengZhi 0336
 * @create: 2025-01-06 20:40
 **/
public class HelpFilter implements FilterHandler<Message, Channel> {

	@Override
	public boolean approve(Message message, Channel obj, FilterHandlerContext<Message,Channel> handlerContext) {

		Object contentOriginal = message.getContent();
		if (contentOriginal instanceof String) {
			String content = (String) contentOriginal;
			if (content.trim().startsWith(Commands.HELP.getCommand())) {
				LogUtils.print(JefClolorEnum.WHITE,"---------------------------------常用指令---------------------------------");
				int i = 1;
				for (Commands commands : Commands.values()) {
					LogUtils.print(JefClolorEnum.BLUE,"【{}】{}  {}", i, commands.getCommand(), commands.getDesc());
					i++;
				}
				LogUtils.print(JefClolorEnum.WHITE,"---------------------------------------------------------------------------");
				return true;
			}
		}
		return handlerContext.doFilter(message, obj);
	}
}
